#include "list.c"

typedef struct
{
   int id_num;
   char name[20];
} LIST_DATA;

int compare (void *l1, void *l2)
{
   LIST_DATA *a;
   LIST_DATA *b;
   a = l1;
   b = l2;
   if (a->id_num < b->id_num)
      return -1;
   else if (a->id_num > b->id_num)
      return TRUE;
   else 
      return FALSE;
}

LIST *add_items(void)
{  
   LIST *plist;
   LIST_DATA *ldata;
   int id = 1;
   
   // Create the list node that keeps track of everything
   plist = create_list (compare);
   while (id != 0)
   {
      printf ("\n Enter an id number: ");
      scanf ("%d", &id);
      if (id)
      {
         ldata = (LIST_DATA *) malloc (sizeof (LIST_DATA));
         ldata->id_num = id;
         printf ("\nEnter a name: ");
         scanf ("%s", ldata->name);
        
         if (add_node (plist, ldata)==0)
         {
            printf ("\n Successful add");
         } 
      }
   }
   return plist;
}

int main (void)
{
   LIST *plist;
   LIST_DATA *ldata;
   int del_node;
   
   // Add the data to a list
   plist = add_items();
   
//   retrieve_node(plist, &(plist->head), (void *) &ldata); 
//   printf ("\n %d %s", ldata->id_num, ldata->name);
 
   printf ("Count %d", plist->count);
   traverse (plist, 0, (void *)&ldata);
   do
   {
       printf ("\n %d %s", ldata->id_num, ldata->name);
   } while (traverse (plist, 1, (void *)&ldata));
   
#if 0
   printf ("\n Select a node to delete: ");
   scanf ("%d", &del_node);
   
   remove_node (plist, &del_node, (void *)&ldata);
   printf ("\n data was removed from node %d", ldata->id_num);
   
   // New list
   traverse (plist, 0, (void *)&ldata);
   do
   {
       printf ("\n %d %s", ldata->id_num, ldata->name);
   } while (traverse (plist, 1, (void *)&ldata));
#endif

  
   
   system ("PAUSE");
   return 0;
}
